﻿using System;
using System.ComponentModel.Composition;
using System.Reflection;
using System.Windows.Controls;
using DesktopInfo;
using GMap.NET;
using Windows7.Location;

namespace Map
{
    /// <summary>
    /// Interaction logic for UserControl1.xaml
    /// </summary>
    [Export(typeof(IDesktopInfoPlugin))]
    [ExportMetadata("Map", "Map")]
    public partial class MapControl : UserControl, IDesktopInfoPlugin
    {
        public MapControl()
        {
            InitializeComponent();

            Singleton<GMaps>.Instance.Mode = AccessMode.ServerOnly;
            gMap.MaxZoom = 0x11;
            gMap.MinZoom = 5;
            gMap.Zoom = 12;



            LatLongLocationProvider location = new LatLongLocationProvider(100);
            if (location.ReportStatus == ReportStatus.Running)
            {
                location.LocationChanged += new LocationChangedEventHandler(location_LocationChanged);
            }
            else if (location.ReportStatus == ReportStatus.AccessDenied)
            {
                //label1.Content = "Cannot retrieve information";
            }


        }



        void location_LocationChanged(LocationProvider locationProvider, LocationReport newLocation)
        {
            var location = (LatLongLocationReport)locationProvider.GetReport();

            this.InvokeIfRequired((value) => gMap.CurrentPosition = new PointLatLng(location.Latitude, location.Longitude), String.Empty);


        }

        public string Autor
        {
            get { return "Arkadiusz Benedykt"; }
        }

        public string Version
        {
            get { return Assembly.GetExecutingAssembly().ImageRuntimeVersion; }
        }

        public string PluginName
        {
            get { return "Where am I"; }
        }

        public string Desciption
        {
            get { return "This plugin shows the map of the area near you"; }

        }
    }
}
